package com.linsir.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.linsir.handler.FillMetaObjectHandler;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ProjectName:linsir
 * @Package:com.linsir.config
 * @Title: MybatisPlusConfig
 * @Description: TODO
 * @Create:2021/5/29 13:36 by @author:Linsir
 * @Update:2021/5/29 13:36 by @author:Linsir
 * @UpdateRemark: 初始创建
 * @Version 1.0.0
 */
@Configuration
@MapperScan(basePackages = "com.linsir.lin.mapper")
public class MybatisPlusConfig {

    @Bean(name = "linglobalConfig")
    public GlobalConfig globalConfig() {
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setMetaObjectHandler(new FillMetaObjectHandler());
        return globalConfig;
    }


    @Bean(name = "linMybatisPlusInterceptor")
    public MybatisPlusInterceptor mybatisPlusInterceptor()
    {
        //  插件
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 分页插件
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
        paginationInnerInterceptor.setOverflow(true);
        // 添加分页插件
        interceptor.addInnerInterceptor(paginationInnerInterceptor);
        return interceptor;
    }



}
